package com.swing.sky.system.framework.security.service;

import com.swing.sky.system.module.domain.SysUserDO;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;

/**
 * \u6B64\u4FE1\u606F\u5728\u8BA4\u8BC1\u6210\u529F\u540E\u5C06\u4F5C\u4E3A authentication \u4E2D\u7684 principal
 */
public class UserDetailsImpl implements UserDetails {
    /**
     * \u6570\u636E\u5E93\u7528\u6237\u4FE1\u606F(\u5C06\u5176\u5305\u88C5\u5728userDetails\u4E2D)
     */
    private SysUserDO userDO;

    public UserDetailsImpl() {
    }

    public UserDetailsImpl(SysUserDO userDO) {
        this.userDO = userDO;
    }

    /**
     * \u8FD4\u56DE\u6388\u4E88\u7528\u6237\u7684\u6743\u9650
     *
     * @return \u6743\u9650\u96C6\u5408
     */
    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return null;
    }

    @Override
    public String getPassword() {
        return userDO.getPassword();
    }

    @Override
    public String getUsername() {
        return userDO.getUsername();
    }

    /**
     * \u8D26\u6237\u662F\u5426\u672A\u8FC7\u671F,\u8FC7\u671F\u65E0\u6CD5\u9A8C\u8BC1
     */
    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    /**
     * \u6307\u5B9A\u7528\u6237\u662F\u5426\u89E3\u9501,\u9501\u5B9A\u7684\u7528\u6237\u65E0\u6CD5\u8FDB\u884C\u8EAB\u4EFD\u9A8C\u8BC1
     */
    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    /**
     * \u6307\u793A\u662F\u5426\u5DF2\u8FC7\u671F\u7684\u7528\u6237\u7684\u51ED\u636E(\u5BC6\u7801),\u8FC7\u671F\u7684\u51ED\u636E\u9632\u6B62\u8BA4\u8BC1
     */
    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    /**
     * \u662F\u5426\u53EF\u7528 ,\u7981\u7528\u7684\u7528\u6237\u4E0D\u80FD\u8EAB\u4EFD\u9A8C\u8BC1
     */
    @Override
    public boolean isEnabled() {
        return true;
    }

    public SysUserDO getUserDO() {
        return userDO;
    }

    public void setUserDO(SysUserDO userDO) {
        this.userDO = userDO;
    }
}